home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_03_02 / 3n02071a < prev    next >
Text File  |  1991-10-12  |  4KB  |  130 lines

  1. 'Demo of CALL INTERRUPT using mouse functions
  2. '       Noel Nyman   8/91 
  3.  
  4. DEFINT A-Z
  5. '$INCLUDE: 'qb.bi' 
  6. DECLARE SUB Mouse (MouseFunction, Buttons, HorizPos, VertPos) 
  7.  
  8. 'declare variables passed to SUB Mouse()
  9. DIM MouseFunction, Buttons, HorizPos, VertPos, MinPos, MaxPos
  10.         
  11. 'define global Booleans       
  12. TRUE = -1
  13. FALSE = NOT TRUE
  14.  
  15. 'define mouse functions
  16. Installed = 0           'check for mouse installed, reset
  17. Show = 1                'show cursor
  18. Hide = 2                'hide cursor
  19. GetPos = 3              'get mouse position and button status
  20. SetPos = 4              'set mouse cursor position
  21.                      
  22. GetPress = 5            'get button press info
  23. GetRelease = 6          'get buton release info
  24. SetHorizRange = 7       'set min/max horiz position
  25. SetVertRange = 8        'set min/max vert position
  26. SetGraphics = 9         'set graphics cursor block
  27.  
  28. SetText = 10            'set text cursor
  29. ReadMotion = 11         'read motion counters
  30. SetMask = 12            'set user sub input mask
  31. PenOn = 13              'light pen emulation on
  32. PenOff = 14             'light pen emulation off
  33.  
  34. Mickey = 15             'set mickey/pixel ratio
  35. CondOff = 16            'conditional off
  36. DoubleSpeed = 19        'set double speed threshold
  37.  
  38. '--- main code starts here ---
  39. CLS
  40. PRINT "Demo of CALL INTERRUPT using mouse functions."
  41. PRINT
  42.  
  43. 'check for a mouse and mouse driver
  44. MouseFunction = Installed
  45. CALL Mouse(MouseFunction, 0, 0, 0)
  46.  
  47. IF MouseFunction THEN
  48.         PRINT "Mouse installed."
  49.  
  50.         'show the text cursor
  51.         MouseFunction = Show
  52.         CALL Mouse(MouseFunction, 0, 0, 0)
  53.  
  54.         'limit mouse to the lower left of the screen
  55.         MouseFunction = SetHorizRange
  56.         MinPos = 0
  57.         MaxPos = 240
  58.         CALL Mouse(MouseFunction, 0, MinPos, MaxPos)
  59.  
  60.         MouseFunction = SetVertRange
  61.         MinPos = 96
  62.         MaxPos = 176
  63.         CALL Mouse(MouseFunction, 0, MinPos, MaxPos)
  64.  
  65.         'Get mouse position and button status, exit on right button down
  66.         PRINT
  67.         PRINT "To test, move the mouse and press the left button ..."
  68.         PRINT "     Press the right button to exit."
  69.  
  70.         ExitDemo = FALSE
  71.         DO
  72.                 'get mouse position and button status
  73.                 MouseFunction = GetPos
  74.                 CALL Mouse(MouseFunction, Buttons, HorizPos, VertPos)
  75.                         LOCATE 8, 1
  76.                         PRINT "Horizontal position: "; HorizPos
  77.  
  78.                         LOCATE 9, 1
  79.                         PRINT "Vertical position:   "; VertPos
  80.  
  81.                 IF Buttons AND 1 THEN
  82.                         LOCATE 11, 1
  83.                         PRINT "Left Button down"
  84.                 ELSE
  85.                         LOCATE 11, 1    'left button not down
  86.                         PRINT SPACE$(16)
  87.                 END IF
  88.  
  89.                 IF Buttons AND 2 THEN
  90.                         LOCATE 12, 1
  91.                         PRINT "Right Button down"
  92.                         ExitDemo = TRUE
  93.                 END IF
  94.  
  95.         LOOP WHILE NOT ExitDemo
  96.        
  97.         LOCATE 14, 1
  98.         PRINT "Demo ended by right button press."
  99.  
  100.         'turn mouse cursor off
  101.         MouseFunction = Hide
  102.         CALL Mouse(MouseFunction, 0, 0, 0)
  103.  
  104. ELSE
  105.         PRINT "Mouse not installed."
  106. END IF
  107.  
  108. END
  109.  
  110.  
  111.  
  112. 'Call mouse driver through interrupt H33. 
  113.  
  114. SUB Mouse (MouseFunction, Buttons, HorizPos, VertPos) 
  115.  
  116.    DIM Regs AS RegType
  117.    Regs.ax = MouseFunction
  118.    Regs.bx = Buttons
  119.    Regs.cx = HorizPos
  120.    Regs.dx = VertPos
  121.    CALL Interrupt(&H33, Regs, Regs)
  122.  
  123.    'return variables from mouse driver
  124.    MouseFunction = Regs.ax
  125.    Buttons = Regs.bx
  126.    HorizPos = Regs.cx
  127.    VertPos = Regs.dx
  128.  
  129. END SUB
  130.